<extend name="Public:index" />
<block name="title">
	<title>分配角色功能代码</title>
</block>
<block name="mycss">
	<style type="text/css">
		.tip {
			width: 280px;
			padding: 10px;
			text-align: center;
			background-color: #5cb85c;
			color: #fff;
			position: fixed;
			top: 10px;
			left: 50%;
			z-index: 100001;
			margin-left: -150px;
			box-shadow: 1px 1px 5px #333;
			-webkit-box-shadow: 1px 1px 5px #333;
		}

		.inputx {
			width: 100%;
		}
	</style>
</block>
<block name="main-crumb">
	<li class="active">分配角色功能代码</li>
</block>
<block name="main-content">
	<div class="container-fluid">
		<div class="row">
			<div class="col-12">
				<div class="card">
					<div class="card-body">
						<div class="page-content">
							<iframe name="ajaxifr" style="display:none;"></iframe>
							<a class="btn btn-default pull-right" role="button" href="{:U('index')}"><i class="ace-icon fa fa-reply"></i> 返回</a>
							<h3 class="text-center">【{$Think.get.rolename}】设置控制权限</h3>
							<table class="table table-bordered table-striped table-hover m_table_miw">
								<thead class="thin-border-bottom">
									<tr>
										<th>选择</th>
										<th>代码</th>
										<th>功能名称</th>
										<th>描述</th>
									</tr>
								</thead>
								<tbody>
									<volist name="list" id="vo" empty="$empty">
										<tr>
											<td width="5%">
												<label>
													<input class="ace chk" type="checkbox" value="{$vo.code}" {:in_array($vo['code'], $codes) ? 'checked' : ''
													 }>
													<span class="lbl"></span>
												</label>
											</td>
											<td>{$vo.code}</td>
											<td>{$vo.name}</td>
											<td>{$vo.intro}</td>
										</tr>
									</volist>
								</tbody>
							</table>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</block>
<block name="myscript">
	<script>
		$(function () {

			$(document).on('click', '.chk', function () {
				var url = "{:U('setRoleCode')}";
				var roleid = "{$Think.get.roleid}";
				var code = [];
				$('.chk:checked').each(function () {
					code.push($(this).val());
				});

				if (roleid) {
					$.post(url, { roleid: roleid, code: code }, function (res) {
						if (res == '1') {
							notify('保存成功！');
						} else {
							notify('保存失败！');
						}
					});
				} else {
					notify('参数错误！');
				}
			});
		});
		//消息通知
		function notify(msg, func) {
			$("<div>")
				.appendTo(document.body)
				.text(msg)
				.addClass("tip")
				.position({
					my: "center top",
					at: "center top",
					of: window
				})
				.show({
					effect: "blind"
				})
				.delay(1500)
				.hide({
					//effect: "blind",
					duration: "slow",
					complete: function () {
						$(this).remove();
						if (typeof func != "undefined")
							func.call();
					}
				});
		}
	</script>
</block>